package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class jdbc_test4 {
    //jdbc中事物为自动提交
    //执行一条SQL语句则提交一次
    //setAutoCommit设置自动提交
    //rollback回滚
    //commit()
    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement ps =null;
        ResultSet rs =null;

        try {
            conn = DBUtil.connection();
            //取消自动提交
            conn.setAutoCommit(false);
            String sql = "";
            ps = conn.prepareStatement(sql);
            ps.setString(1,"");
            ps.setString(2,"");
            rs = ps.executeQuery();
            while(rs.next()){
                System.out.println();
            }

            conn.commit();
        } catch (SQLException e) {
            if(conn!=null){
                try {
                    conn.rollback();
                } catch (SQLException ex) {
                    throw new RuntimeException(ex);
                }
            }
            throw new RuntimeException(e);
        } finally{
            DBUtil.close(conn,ps,rs);
        }
    }
}
